package GUI;
/**hofit**/

import javax.swing.*;
import java.awt.*;

import javax.swing.JTextField;

import java.awt.Font;
import javax.swing.JButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicTabbedPaneUI.TabbedPaneLayout;

import Client.BusinessImplements;
import Controler.Log_in_panel_controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Sign_in_panel extends Abstract_Jpanel {
	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
	
	
	private final JLabel lblWelcomToThe = new JLabel("welcome to the library application");
	public final JButton btnlogout = new JButton("log out");
	
	private Lend_book_panel lend_book;
	private Update_Member_Card_Secondary up_memmber_card;
	private Update_Member_Card_Primary up_memmber_card_primary;
	private Create_NewMember_panel create_member;
	public Managment_choice_panel managment_choice;
	private Extend_Item_Panel extend_item;
    public Search_an_Item search_item;
    public  Member_Card_Select_Member member_history_select;
  	public  Reports_panel reports;
  	public Put_Id_for_Extend put_id_for_extend;
  	private Return_Book_panel return_book;
	/**
	 * Create the panel.
	 */
	public Sign_in_panel() {
		member_history_select=new Member_Card_Select_Member();
		lend_book=new Lend_book_panel();
		create_member=new Create_NewMember_panel();
		managment_choice=new Managment_choice_panel();
		extend_item=new Extend_Item_Panel(); 
		search_item=new Search_an_Item();
		reports=new  Reports_panel();
		up_memmber_card=new Update_Member_Card_Secondary ();
		up_memmber_card_primary=new Update_Member_Card_Primary ();
		put_id_for_extend = new Put_Id_for_Extend();
		return_book=new Return_Book_panel();
		initGUI();
	
	}
	private void initGUI() {
		setBackground(new Color(240, 240, 240));
		setLayout(null);
		Toolkit tk = Toolkit.getDefaultToolkit();
		int xSize = ((int) tk.getScreenSize().getWidth());
		int ySize = ((int) tk.getScreenSize().getHeight());
	
		
		btnlogout.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				Log_in_panel_controler con_log= new Log_in_panel_controler();
				con_log.update_useroffline(Integer.toString(BusinessImplements.GetInstance().getUserLogin().getUserID()));
				Log_in_panel lg=new Log_in_panel();
				BusinessImplements.GetInstance().getMainFrame().setBounds(100, 100, 499, 337);
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(lg);
				lg.setSize(getMaximumSize());
				lg.on_screen_load();
				
			}
		});
		create_member.setLayout(null);
		
		
		
		lend_book.setLayout(null);
		
		managment_choice.setLayout(null);
		
		tabbedPane.setBackground(new Color(211, 211, 211));
		
		
	tabbedPane.setSize(xSize, ySize-100);
		//tabbedPane.setBounds(0, 0, 501, 332);
		
		add(tabbedPane);
		
				
				
		
	
		Welcome_panel welcome_panel=new Welcome_panel();
		tabbedPane.addTab("main menu", null, welcome_panel, null);
		//panel.setLayout(null);
		lblWelcomToThe.setForeground(new Color(25, 25, 112));
		lblWelcomToThe.setFont(new Font("Vivaldi", Font.BOLD, 32));
		lblWelcomToThe.setBounds(39, 47, 392, 39);
		
		
		
		tabbedPane.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent arg0) {
				
				   ((Abstract_Jpanel)tabbedPane.getSelectedComponent()).on_screen_load();
				 
				
			}
		});
		
		
		//btnlogout.setBounds(174, 317, 89, 23);
		btnlogout.setBounds(174, ySize-95, 89, 23);
		add(btnlogout);
	}
	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void on_screen_load() {
		tabbedPane.addTab("search", null,search_item, null);
		if (BusinessImplements.GetInstance().getUserLogin().getUserPosition()==1)
			{
				tabbedPane.addTab("extend", null, (extend_item=new Extend_Item_Panel()), null);
				tabbedPane.addTab("update reader card", null,up_memmber_card, null);
			}
		if (BusinessImplements.GetInstance().getUserLogin().getUserPosition()>=1)
			{	
				tabbedPane.addTab("member card", null, member_history_select, null);
				
				
			}
		if (BusinessImplements.GetInstance().getUserLogin().getUserPosition()>=2)
			{
			    tabbedPane.addTab("return item", null, return_book, null);
				tabbedPane.addTab("lend", null, lend_book, null);
				tabbedPane.addTab("managment", null, managment_choice, null);
				tabbedPane.addTab("extend", null, put_id_for_extend, null);
				//tabbedPane.addTab("Mantaince", null, panel_7, null);
			}
		if (BusinessImplements.GetInstance().getUserLogin().getUserPosition()>=3)	
			tabbedPane.addTab("reports", null,reports, null);}		
	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
}
